package com.lty.jeeg.server.modules.fas.controller;

import com.lty.jeeg.server.common.dto.ResponseInfo;
import com.lty.jeeg.server.common.page.table.PageTableRequest;
import com.lty.jeeg.server.common.page.table.PageTableResponse;
import com.lty.jeeg.server.common.utils.BeanConverter;
import com.lty.jeeg.server.common.utils.ResponseUtil;
import com.lty.jeeg.server.modules.fas.dto.BorrowDTO;
import com.lty.jeeg.server.modules.fas.service.BorrowService;
import com.lty.jeeg.server.modules.fas.vo.BorrowVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author : xuchen
 * @date : 2019-03-02
 * Description : 借用
 */
@Api(tags = "借用")
@RestController
@RequestMapping("/borrow")
public class BorrowController {

    private final BorrowService borrowService;

    @Autowired
    public BorrowController(BorrowService borrowService) {
        this.borrowService = borrowService;
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id获取")
    public ResponseInfo get(@PathVariable Long id) {
        return ResponseUtil.success(BeanConverter.map(borrowService.getById(id), BorrowVO.class));
    }

    @PostMapping
    @ApiOperation(value = "保存")
    public ResponseInfo save(@RequestBody BorrowVO borrowVO) {
        return ResponseUtil.success(borrowService.save(BeanConverter.map(borrowVO, BorrowDTO.class)));
    }

    @PutMapping
    @ApiOperation(value = "修改")
    public ResponseInfo update(@RequestBody BorrowVO borrowVO) {
        return ResponseUtil.success(borrowService.update(BeanConverter.map(borrowVO, BorrowDTO.class)));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除")
    public ResponseInfo delete(@PathVariable Long id) {
        return ResponseUtil.success(borrowService.delete(id));
    }

    @GetMapping("/list")
    @ApiOperation(value = "列表")
    public PageTableResponse list(PageTableRequest request) {
        return borrowService.list(request);
    }

    @PostMapping("/approval")
    @ApiOperation(value = "审核")
    public String approval(@RequestParam(value = "id",required = true)Long id,@RequestParam("flowState")String flowState) {
        return borrowService.approval(id,flowState);
    }


}

